<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script src="js/jquery-1.7.1.js"></script>
<script src="js/jquery.form.js"></script>
<script type="text/javascript">
$(document).ready(function () {

});

function postUpload(){
	for(i=0;i<$("#counts").val();i++){
		var fileName=$("#file").val();
		fileName=fileName.substring(fileName.lastIndexOf("\\")+1);
		$("#fileName").val(fileName);
	    var options = {

	    	 url: $("#url").val()+"uploadFile.hc",
	    	 type:'post',
	    	 dataType:"json",
			 success: function(obj) {
				 $("#resultDiv").html("");


				 if(obj.data.status!="1"){
					 alert(obj.data.message);
					 return;
				 }

				 var fsId=obj.data.fsId;
				 var url=$("#url").val()+"downloadFile.hc?fsId="+fsId;
				 var slaveName=$("#slaveName").val();
				 var fileType=$("#fileType").val();
				 if(fileType=="IMG"){
					 var masterHtml="<img id='masterFile' src='"+url+"'>";
					 $("#resultDiv").append(masterHtml);
					 if(slaveName!=""){
						 var slaveArr=slaveName.split(",");
						 for(var i=0;i<slaveArr.length;i++){
							 var slaveHtml="<img id='file0"+i+"' src='"+url+"&slaveName="+slaveArr[i]+"'>";
							 $("#resultDiv").append(slaveHtml);
						 }
					 }
				 }else{
					 var masterHtml="<a id='masterFile' href='"+url+"' target='_blank'>下载文件</a>";
					 $("#resultDiv").append(masterHtml);
				 }
	         }
		};
		// 提交表单
		$('#uploadForm').ajaxSubmit(options);
	}
}



</script>
</head>
<body>
	<form  id="uploadForm" name="uploadForm" method="POST" enctype="multipart/form-data">

            <table width="100%" bolder="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td align="left">
                    	http://localhost:8080/fastdfs-api/<br>
                    	http://filesys-test.hengchang6.com:8080/fs-api/<br>
                    	http://filesys-test.hengchang6.com:8080/fastdfs-api/<br>
                    	http://filesys-test.hengchang6.com/fs-api/<br>

                        url:<input type="text" id="url"  name="url" value="" /><br>

                        file:<input id="file" name="file" type="file"/><br>
                        businessId:<input type="text" id="businessId"  name="businessId" value="business000002" /><br>
                        systemId:<input type="text" id="systemId" name="systemId" value="sanbiao" /><br>
                        fileName:<input type="text" id="fileName" name="fileName" value="test.jpg" /><br>
                        fileType:<select id="fileType" name="fileType" >
                        	<option value="IMG">IMG</option>
                        	<option value="DOC">DOC</option>
                        </select><br>
                        slaveName:<input type="text" id="slaveName" name="slaveName" value="32X32,100X100,380-285T650-515" /><br>
                        upload&downloadCounts:<input type="text" id="counts" name="counts" value="10" /><br>
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="2">
						<input id="button" type="button" value="上传" onclick="postUpload()" />
                    </td>
                </tr>
            </table>
        </form>
        <div id="resultDiv">
         	<img id="file01" src="http://filesystem.credithc.com/fs-api/downloadFile.hc?fsId=165A405B0ABA6CE8E0531664A8C03443&slaveName=32X32">
        	<img id="file02"  src="http://filesystem.credithc.com/fs-api/downloadFile.hc?fsId=165A405B0ABA6CE8E0531664A8C03443&slaveName=100X100">
        	<img id="file03"  src="http://filesystem.credithc.com/fs-api/downloadFile.hc?fsId=165A405B0ABA6CE8E0531664A8C03443&slaveName=380-285T650-515">
        </div>

    <br>
</body>
</html>